package com.sicheng.hello.controller;

import com.sicheng.hello.service.AsyncService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/9/30 10:34
 */

//@AESEncryptBody
@RestController
public class HelloController {

    @Resource
    private AsyncService asyncService;

    @GetMapping("/hello")
    public String hello() {
        return "hello springboot<br>  35 杨腾飞 ";
    }

    @GetMapping("/sync")
    public String sync(Integer millis1, Integer millis2) {
        long start = System.currentTimeMillis();
        Future<Integer> future1 = asyncService.executeAsyncWithFuture(millis1);
        Future<Integer> future2 = asyncService.executeAsyncWithFuture(millis2);

        try {
            future1.get();
            future2.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        long spend = System.currentTimeMillis() - start;

        return "花费" + spend + "millis";
    }
}
